#pragma once

#include <map>
#include <vector>

#include "DeviceEnumerator.h"

#include <rt/Exceptions/NotImplementedException.h>

inline bool operator<(D3DDISPLAYMODE const &lhs, D3DDISPLAYMODE const &rhs)
{
	if (lhs.Width == rhs.Width)
	{
		if (lhs.Height == rhs.Height)
		{
			if (lhs.RefreshRate == rhs.RefreshRate)
			{
				return lhs.Format < rhs.Format;
			}
			else
			{
				return lhs.RefreshRate < rhs.RefreshRate;
			}
		}
		else
		{
			return lhs.Height < rhs.Height;
		}
	}
	return lhs.Width < rhs.Width;
}

class FakeDeviceEnumerationFilter : public rt::IDeviceEnumerationFilter
{
public:
	explicit FakeDeviceEnumerationFilter()
		: IsDeviceAcceptableCalled(false),
		IsDeviceAcceptableLastCaps(),
		IsDeviceAcceptableLastAdapterFormat(D3DFMT_UNKNOWN),
		IsDeviceAcceptableLastBackBufferFormat(D3DFMT_UNKNOWN),
		IsDeviceAcceptableLastWindowed(false),
		IsDeviceAcceptableFakeResult(false)
	{
	}

	virtual ~FakeDeviceEnumerationFilter() { }

	virtual bool IsDisplayModeAcceptable(D3DDISPLAYMODE const &mode)
	{
		IsDisplayModeAcceptableLastMode.push_back(mode);
		return IsDisplayModeAcceptableFakeResult[mode];
	}
	std::vector<D3DDISPLAYMODE> IsDisplayModeAcceptableLastMode;
	std::map<D3DDISPLAYMODE, bool> IsDisplayModeAcceptableFakeResult;

	virtual bool IsDeviceAcceptable(D3DCAPS9 const &caps,
		D3DFORMAT adapterFormat, D3DFORMAT backBufferFormat, bool windowed)
	{
		IsDeviceAcceptableCalled = true;
		IsDeviceAcceptableLastCaps = caps;
		IsDeviceAcceptableLastAdapterFormat = adapterFormat;
		IsDeviceAcceptableLastBackBufferFormat = backBufferFormat;
		IsDeviceAcceptableLastWindowed = windowed;
		return IsDeviceAcceptableFakeResult;
	}
	bool IsDeviceAcceptableCalled;
	D3DCAPS9 IsDeviceAcceptableLastCaps;
	D3DFORMAT IsDeviceAcceptableLastAdapterFormat;
	D3DFORMAT IsDeviceAcceptableLastBackBufferFormat;
	bool IsDeviceAcceptableLastWindowed;
	bool IsDeviceAcceptableFakeResult;
};
